home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / lu62 / allocate.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  7KB  |  261 lines

  1. /*
  2.  *                    ALLOCATE
  3.  *
  4.  * Function: This function is intended to allocation
  5.  *           resources for transaction program.
  6.  *           The Resource Control Block will be created
  7.  *           in case if all supplied parameters are correct.
  8.  *
  9.  *           For detailed description of the ALLOCATE request
  10.  *           see the "SNA Transaction Programmer's Reference Manual".
  11.  *
  12.  * Input: ALLOCATE structure.
  13.  * Output: a return code in the ALLOCATE structure.
  14.  *
  15.  * CopyRight 1995. Nicholas Poljakov all rights reserved.
  16.  *
  17.  */
  18. #include <alloc.h>
  19. #include <tcb.h>
  20. #include <mode.h>
  21. #include <lucb.h>
  22. #include <arcb.h>
  23. #include <state1.h>
  24. #include <rcballoc.h>
  25. #include <partner.h>
  26. #include <repass.h>
  27. #include <rcb.h>
  28. #include <stdio.h>
  29. #include <malloc.h>
  30. #include <string.h>
  31. #if OS_TYPE == 1
  32. #include <memory.h>
  33. #endif
  34.  
  35. struct psp {
  36.        struct lucb *lucb_list_ptr; /* pointer to lucb list */
  37.        struct tcb  *tcb_list_ptr ; /* pointer to tcb  list */
  38.        struct rcb  *rcb_list_ptr ; /* pointer to rcb  list */
  39.        char    *param;
  40.      } psp_ini;
  41.  
  42. int sk_r_wt(void *);
  43. int SendBlock(void *, void *);
  44. int setrc(void *, void *);
  45. int sendhsf(void *);
  46. int sendhs(void *);
  47. int sendbm(void *, void *);
  48. int sendat(void *);
  49. int rtsend(void *);
  50. unsigned long rmfmh5(void *, void *);
  51. int recwait(void *);
  52. int rcvru(void *, void *);
  53. int rcvhs(void *, void *, void *, void *);
  54. int ralloc(void *, void *);
  55. int psrm(int, void *, void *);
  56. int ps_conv(int, void *);
  57. int proterr(void *, unsigned long);
  58. int preptrcv(void *, void *);
  59. int post_rcb(void *);
  60. struct repass *postopen(void *);
  61. int phsrec(void *);
  62. int pfmh5(void *);
  63. int opndst(void *);
  64. int obtsess(void *, unsigned char);
  65. int Lrf_handler(void *);
  66. int get_sess(void *, void *);
  67. int get_attr(void *);
  68. int fsm_error(unsigned char, void *);
  69. int fsm_conv(unsigned char, unsigned char, void *);
  70. int flush (void *);
  71. int dcp(void *);
  72. int dealloc(void *);
  73. int crtp(void *);
  74. int conv(void *);
  75. int chkparm(void *, void *);
  76. int check_end(unsigned int, void *);
  77. struct rqb *call_appl(void *);
  78. int buffmng(unsigned char, void *, void *, void *, unsigned, unsigned char, unsigned);
  79. unsigned long attltck(void *);
  80. unsigned long attacheck(void *);
  81. char *cgetmem(int, int);
  82. int sendhsf(void *);
  83. int opndst(void *);
  84. int alloc_rcb(void *, void *);
  85. int clsdst(void *);
  86.  
  87. allocate(pptr)
  88. struct allocate *pptr;
  89.  {
  90. struct arcb *alloc_rcb;
  91. struct rcballoc *rcb_alloc;
  92. struct mode *temp2;
  93. struct lucb *p_lucb;
  94. struct lucb *temp1;
  95. struct pnlu *temp;
  96. struct pnlu *save;
  97. struct tcb *p_tcb;
  98. struct rcb *p_rcb;
  99. struct repass *p_rep;
  100. int code_rec;
  101. char mode[9];
  102. char lu[9];
  103. char tp[9];
  104. int  i;
  105. int  k;
  106.  
  107. #if OS_TYPE == 1
  108. /*********  Trace facility **********/
  109. unsigned int rtype;   /* type of record */
  110. unsigned int pnum;    /* point number */
  111. char pname[8];        /* name of module */
  112. char *drec;       /* record for dump */
  113. int  lenr;            /* record length */
  114.  
  115. rtype = INPROC;
  116. strcpy(pname, "allocat");
  117. pnum = 1;
  118. drec = pptr;
  119. lenr = sizeof(struct allocate);
  120. gtf(rtype, pname, pnum, drec, lenr);
  121. /***********************************/
  122. #endif
  123.  
  124.     if ((alloc_rcb = calloc(1, sizeof(struct arcb))) == NULL) {
  125.          pptr -> prim_rc = PORT_ABENDED;
  126.          return (0);
  127.     }
  128.     if ((rcb_alloc = calloc(1, sizeof(struct rcballoc))) == NULL) {
  129.          pptr -> prim_rc = PORT_ABENDED;
  130.          free(alloc_rcb);
  131.          return (0);
  132.     }
  133.     p_rep = (struct repass *)pptr;
  134.  
  135.     /* Åα«óÑα¬á ¡á½¿τ¿∩ lu ß ¿¼Ñ¡Ñ¼ ºáñá¡¡δ¼ ó
  136.      * »α¿¼¿Γ¿óÑ allocate.
  137.      */
  138.     for (i = 0; i < 8; i++) {
  139.         lu[i] = pptr -> p_lu_name[i];
  140.         mode[i] = pptr -> mode_name[i];
  141.         tp[i] = pptr -> tp_id[i];
  142.     }
  143.     mode[8] = 0;
  144.     lu[8] = 0;
  145.     tp[8] = 0;
  146.  
  147.     temp1 = psp_ini.lucb_list_ptr;
  148.     p_tcb = temp1 -> tcb_list_ptr;
  149.  
  150. /*
  151.  * Seek for tr. prog. idetifier
  152.  */
  153.     while (p_tcb != NULL) {
  154.        if ((k = memcmp(p_tcb -> tcb_id, tp, 8)) != 0)
  155.              p_tcb = p_tcb -> next;
  156.            else
  157.               break;
  158.     }
  159.     if (p_tcb == NULL) {
  160.        pptr->prim_rc = PARAMETR_CHECK;
  161.        pptr->sec_rc = BAD_TP_ID;
  162.        goto alloc_exit;
  163.     }
  164.     alloc_rcb -> p_tcb = p_tcb; /* Set tcb pointer in alloc_rcb record*/
  165.     p_rep -> tp_fd = p_tcb -> tp_fd;
  166.  
  167.     temp = temp1 -> pluptr;  /* pointer to partner lu */
  168. /*
  169.  * Seek for partner_lu
  170.  */
  171.     while (temp != NULL) {
  172.         if (memcmp(temp -> lu_name, lu, 8) != 0)
  173.            temp = temp -> next;
  174.         else
  175.            break;
  176.     }
  177.     if (temp == NULL) {
  178.        pptr->prim_rc = PARAMETR_CHECK; /* lu which has that name was not found */
  179.        pptr->sec_rc = INVALID_LU_NAME;
  180.        goto alloc_exit;
  181.     }
  182.  
  183.     save = temp; /* Save pointer to partner_lu_block */
  184.  
  185.     temp2 = temp->m_ptr; /* pointer to MODE block */
  186.     if ((k = memcmp(mode, temp2 -> name, 8)) != 0) {
  187.        pptr->prim_rc = PARAMETER_ERROR; /* block mode
  188.                                        * with that name not found */
  189.        pptr->sec_rc = INVALID_MODE_NAME;
  190.        goto alloc_exit;
  191.     }
  192.     if (pptr -> tp_lt == 0)
  193.        goto dcp_ex;
  194.     if (pptr -> conv_type == MAPPED)
  195.        goto dcp_ex; /* mapped conversation not supported*/
  196.     if (pptr -> return_control == DELAYED_ALLOCATION_PERMITED)
  197.        goto dcp_ex; /* this option not supported*/
  198.  
  199.     memcpy(alloc_rcb -> lu_name, pptr -> p_lu_name, 8);
  200.     memcpy(alloc_rcb -> mode_name, pptr->mode_name, 8);
  201.  
  202.    /* Synchronous RM call */
  203.     code_rec = ALLOCATE_RCB;
  204.     psrm(code_rec, alloc_rcb, rcb_alloc);
  205.     p_rcb = rcb_alloc -> rcb_ptr;
  206.     p_rcb -> p_partner = save; /* Pointer to Partner_LU */
  207.     p_rcb -> verb_ptr = pptr;
  208.     p_rcb -> verb_code = Allocate;
  209.  
  210.     if (save -> lu_type == 0) {
  211.       /* Allocate for LU type 0 */
  212.         if (rcb_alloc -> rc == OK) {
  213.              obtsess(p_rcb, ATTACH);
  214.              if (p_rcb -> error_state != NO_RQS) {
  215.                 pptr -> prim_rc = UNSUCCESSFUL;
  216.                 goto alloc_exit;
  217.              }
  218.              pptr -> prim_rc = OK;
  219.          pptr -> conv_id = p_rcb -> rcb_id;
  220.         }
  221.         else
  222.                 pptr -> prim_rc = UNSUCCESSFUL;
  223.         goto alloc_exit;
  224.     }
  225.  
  226.  /* Make the rcb_allocated request for building an FMH-5 and return code
  227.   * setting.
  228.   */
  229.     ralloc(rcb_alloc, pptr);
  230.     goto alloc_exit;
  231.  
  232.  dcp_ex :
  233.     p_lucb = psp_ini.lucb_list_ptr;
  234.     if (p_lucb == NULL) {
  235.         pptr -> prim_rc = PORT_ABENDED;
  236.         goto alloc_exit;
  237.     }
  238.     p_tcb = p_lucb -> tcb_list_ptr;
  239.     if (p_tcb == NULL) {
  240.         pptr -> prim_rc = PORT_ABENDED;
  241.         goto alloc_exit;
  242.     }
  243.     while (p_tcb != NULL) {
  244.         if (memcmp(pptr -> tp_id, p_tcb -> tcb_id, 8) == 0) {
  245.                 goto Call_dcp;
  246.         }
  247.         p_tcb = p_tcb -> next;
  248.     }
  249.     pptr -> prim_rc = PORT_ABENDED;
  250.     goto alloc_exit;
  251.  
  252.  /* Call the deallocation_cleanup procedure because of abend condition */
  253.     Call_dcp :
  254.  
  255.     dcp(p_tcb);
  256.     alloc_exit:
  257.                 free(alloc_rcb);
  258.                 free(rcb_alloc);
  259.                 return (0);
  260. }
  261.